package com.wavecoler.professor.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.wavecoler.professor.dao.TeamDAO;
import com.wavecoler.professor.objects.User;

@SuppressWarnings("serial")
public class getusers extends HttpServlet {

	private static final Logger log = Logger
	.getLogger(getusers.class.getName());
	
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		log.info(request.getParameter("groupname").toString());
		List<User> users = TeamDAO.getTeamUsers(request.getParameter("groupname").toString());
		
		PrintWriter out = response.getWriter();
		if(users!=null){
		out.println("<select id=\"usersingroup\" name=\"usersingroup\" size=\"3\" multiple=\"multiple\" style=\"width: 350px;\">");
		for(int i = 0; i < users.size(); i++){
			out.println("<option>" + users.get(i) + "</option>");
		}
		out.println("</select>");
		}
		else
			log.info("No parameter received");
			

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}
